package 创建线程;

public class Test6 {
    public static void main(String[] args) throws InterruptedException {
        Thread.currentThread().setName("主线程");
        //创建一个线程
        Thread t=new MyThread();
        //为线程设置名称
        t.setName("线程一");
        //开启线程
        t.start();
        while(true){
            System.out.println(Thread.currentThread().getName()+":"+"输出的结果");
            Thread.sleep(1000);
        }
    }
}

class MyThread extends Thread{
    @Override
    public void run() {
        System.out.println(Thread.currentThread().getName()+":"+"输出的结果");
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
    }
}
